package edu.pitt.cs.cs2410pj2.util;

/**
 * The trace of the operation
 * 
 * @author zhangfan
 * 
 */
public class Trace {
	private int cycle;
	private int cordId;
	private boolean typeRead; // true for read, false for write
	private String addr;
	private boolean issued = false;
	private boolean isFinished = false;
	
	private int issuedTime = 0;
	private int finishedTime = 0;

	public boolean isFinished() {
		return isFinished;
	}

	public int getMissPenalty() {
		return finishedTime-issuedTime;
	}
	
	public int getFinishedTime() {
		return finishedTime;
	}
	
	public int getIssuedTime() {
		return issuedTime;
	}
	
	public void setFinished(boolean isFinished,int timeCycle) {
		this.isFinished = isFinished;
		this.finishedTime = timeCycle;
		System.out.println(this);
	}

	public boolean isIssued() {
		return issued;
	}

	public void setIssued(boolean issued,int timeCycle) {
		this.issued = issued;
		this.issuedTime = timeCycle;
	}

	public int getCycle() {
		return cycle;
	}

	public void setCycle(int cycle) {
		this.cycle = cycle;
	}

	public int getCordId() {
		return cordId;
	}

	public void setCordId(int cordId) {
		this.cordId = cordId;
	}

	public boolean isTypeRead() {
		return typeRead;
	}

	public void setTypeRead(boolean type) {
		this.typeRead = type;
	}

	public String getAddr() {
		return addr;
	}

	public void setAddr(String addr) {
		this.addr = addr;
	}

	public String toString() {
		String msg =  "CYCLE:"+this.getCycle() + ",TILE: " + this.getCordId() + ",IS READ: "
				+ this.isTypeRead() + ",BlOCK ADDRESS: " + this.getAddr() + ",IS ISSUED: "
				+ issued + ",IS FINISHED: " + isFinished;
		if(issued) msg+=",ISSUED AT CYCLE: "+issuedTime;
		if(isFinished) msg+= ",FINISHED AT CYCLE: "+finishedTime;
		return msg;
	}

}
